$OpenBSD: patch-libmysql_CMakeLists_txt,v 1.11 2016/05/04 07:37:22 sthen Exp $
--- libmysql/CMakeLists.txt.orig	Thu Apr 28 16:27:44 2016
+++ libmysql/CMakeLists.txt	Sun May  1 23:24:58 2016
@@ -266,6 +266,8 @@ mysql_net_field_length
 mysql_options4
 )
 
+SET(LIBVER_OVERRIDE $ENV{LIBmysqlclient_VERSION})
+
 SET(CLIENT_API_FUNCTIONS
   ${CLIENT_API_FUNCTIONS_5_1}
   ${CLIENT_API_FUNCTIONS_5_5}
@@ -479,8 +481,12 @@ IF(NOT DISABLE_SHARED)
     # libtool compatability
     IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR APPLE)
       SET(OS_SHARED_LIB_VERSION "${SHARED_LIB_MAJOR_VERSION}")
-    ELSEIF(CMAKE_SYSTEM_NAME MATCHES "HP-UX")
-      SET(OS_SHARED_LIB_VERSION "${SHARED_LIB_MAJOR_VERSION}.0")
+    ELSEIF(CMAKE_SYSTEM_NAME MATCHES "HP-UX" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
+      IF(LIBVER_OVERRIDE)
+        SET(OS_SHARED_LIB_VERSION "${LIBVER_OVERRIDE}")
+      ELSE()
+        SET(OS_SHARED_LIB_VERSION "${SHARED_LIB_MAJOR_VERSION}.0")
+      ENDIF(LIBVER_OVERRIDE)
     ELSE()
       SET(OS_SHARED_LIB_VERSION "${SHARED_LIB_MAJOR_VERSION}.0.0")
     ENDIF()
@@ -488,7 +494,7 @@ IF(NOT DISABLE_SHARED)
     SET_TARGET_PROPERTIES(libmysql PROPERTIES 
       OUTPUT_NAME mysqlclient 
       VERSION "${OS_SHARED_LIB_VERSION}" 
-      SOVERSION "${SHARED_LIB_MAJOR_VERSION}")
+      SOVERSION "${OS_SHARED_LIB_VERSION}")
     IF(LINK_FLAG_NO_UNDEFINED OR VERSION_SCRIPT_LINK_FLAGS)
       GET_TARGET_PROPERTY(libmysql_link_flags libmysql LINK_FLAGS)
       IF(NOT libmysql_link_flags)
@@ -507,18 +513,8 @@ IF(NOT DISABLE_SHARED)
     GET_VERSIONED_LIBNAME(
       "${CMAKE_SHARED_LIBRARY_PREFIX}mysqlclient_r"
       "${CMAKE_SHARED_LIBRARY_SUFFIX}"
-      ""
+      "${OS_SHARED_LIB_VERSION}"
       linkname)
-    INSTALL_SYMLINK(${linkname} libmysql ${INSTALL_LIBDIR} SharedLibraries)
-    SET(OS_SHARED_LIB_SYMLINKS "${SHARED_LIB_MAJOR_VERSION}" "${OS_SHARED_LIB_VERSION}")
-    LIST(REMOVE_DUPLICATES OS_SHARED_LIB_SYMLINKS)
-    FOREACH(ver ${OS_SHARED_LIB_SYMLINKS})
-      GET_VERSIONED_LIBNAME(
-        "${CMAKE_SHARED_LIBRARY_PREFIX}mysqlclient_r"
-        "${CMAKE_SHARED_LIBRARY_SUFFIX}"
-        "${ver}"
-        linkname)
-      INSTALL_SYMLINK(${linkname} libmysql ${INSTALL_LIBDIR} SharedLibraries)
-    ENDFOREACH()
+    INSTALL_VERSIONED_SYMLINK(${linkname} libmysql ${INSTALL_LIBDIR} SharedLibraries)
   ENDIF()
 ENDIF()
